Instalador = function(){
	var configWindowTop = {
		add: "instaladorAgregarTop",
		remove: "instaladorEliminarTop",
	};
	return {
		guardarGrupoInstaladores: function(){
			if (Ext.isEmpty(Asi.utils.getValue("NombreGrupo")) || Ext.isEmpty(Instalador.obtenerEstadosInstalador())){
				Asi.message.alertInvalid("Debe Ingresar Nombre del Grupo y Seleccionar Recursos.");
			} else {
				Asi.message.progress(Asi.constants.SAVING);
				Ext.getCmp("instaladorForm").getForm().submit({
					url: Asi.constants.CONTEXT_PATH + "/empleado/guardarGrupoInstaladores",
	    			timeout: Asi.constants.TIMEOUT_SECONDS,
	    			params: {
	    				"idInstalador": Instalador.obtenerIdInstalador(),
	    				"estadoInstalador": Instalador.obtenerEstadosInstalador(),
	    				"nombreGrupo": Asi.utils.getValue("NombreGrupo"),
	    				"empleadoId": AsiGen.getUsuarioId()
	    			},
	    			success: function(form, action){
	    				var grid = Ext.getCmp("instaladorGrid2");
	    				var gridDisponible = Ext.getCmp("instaladorGrid");
	    				grid.getStore().removeAll();
	    				gridDisponible.getStore().removeAll();
	    				Asi.message.alert(action.result.message);
	    				if(action.result.instaladorEnUso){
	    					grid.getStore().loadData(action.result.instaladorEnUso);
	    				}
	    				if(action.result.instaladoresDisponibles){
	    					gridDisponible.getStore().loadData(action.result.instaladoresDisponibles);
	    				}
	    			},
	    			failure: Asi.form.failureProcedure
				});
				Asi.utils.setValue("NombreGrupo", "");
			}
		},
		obtenerIdInstalador: function(){
			var i = 0;
			var grid = Ext.getCmp("instaladorGrid");
			var seprarado = "~";
			var gridData = "";
			Ext.each(grid.getStore().getRange(), function(){
				gridData = gridData + Ext.getCmp("instaladorGrid").getStore().getRange()[i].data.id + seprarado;
				i++;
          });
			return gridData == "~" ? "":gridData;
		},
		obtenerEstadosInstalador: function(){
			var i = 0;
			var grid = Ext.getCmp("instaladorGrid");
			var seprarado = "~";
			var gridData = "";
			Ext.each(grid.getStore().getRange(), function(){
				gridData = gridData + Ext.getCmp("instaladorGrid").getStore().getRange()[i].data.usuarioActivo + seprarado;
				i++;
          });
			return gridData == "~" ? "":gridData;
		},
		eliminarInstaladoresDeGrupo: function(){
			if (Ext.isEmpty(Instalador.obtenerEstadosInstaladorEliminar())){
				Asi.message.alertInvalid("Debe Seleccionar Recursos Para Poder Continuar.");
			} else {
			Asi.message.progress(Asi.constants.SAVING);
				Ext.getCmp("instaladorForm").getForm().submit({
					url: Asi.constants.CONTEXT_PATH + "/empleado/actualizarGrupoInstaladores",
	    			timeout: Asi.constants.TIMEOUT_SECONDS,
	    			params: {
	    				"idInstalador": Instalador.obtenerIdInstaladorEliminar(),
	    				"estadoInstalador": Instalador.obtenerEstadosInstaladorEliminar()
	    			},
	    			success: function(form, action){
	    				var grid = Ext.getCmp("instaladorGrid2");
	    				var gridDisponible = Ext.getCmp("instaladorGrid");
	    				grid.getStore().removeAll();
	    				gridDisponible.getStore().removeAll();
	    				Asi.message.alert(action.result.message);
	    				if(action.result.instaladorEnUso){
	    					grid.getStore().loadData(action.result.instaladorEnUso);
	    				}
	    				if(action.result.instaladoresDisponibles){
	    					gridDisponible.getStore().loadData(action.result.instaladoresDisponibles);
	    				}
	    			},
	    			failure: Asi.form.failureProcedure
				});
			}
		},
		obtenerIdInstaladorEliminar: function(){
			var i = 0;
			var grid = Ext.getCmp("instaladorGrid2");
			var seprarado = "~";
			var gridData = "";
			Ext.each(grid.getStore().getRange(), function(){
				gridData = gridData + Ext.getCmp("instaladorGrid2").getStore().getRange()[i].data.instaladorId + seprarado;
				i++;
          });
			return gridData == "~" ? "":gridData;
		},
		obtenerEstadosInstaladorEliminar: function(){
			var i = 0;
			var grid = Ext.getCmp("instaladorGrid2");
			var seprarado = "~";
			var gridData = "";
			Ext.each(grid.getStore().getRange(), function(){
				gridData = gridData + Ext.getCmp("instaladorGrid2").getStore().getRange()[i].data.instaladorEstado + seprarado;
				i++;
          });
			return gridData == "~" ? "":gridData;
		},
		
		init: function(config){
			var configToReturn = {};
			configToReturn.items = [];
			configToReturn.menu = AsiBotones.getBotones(AsiGen.getTipoUsuario(), AsiGen.getPantallaId());
			configToReturn.items.push({
				flex: 1,
				title: "REQUISICION DE INVENTARIO",
				autoScroll: true,
				layout : {
					type : "table",
					columns : 1,
					tableAttrs : {
						style : {
							width : "730px",
							"margin-top" : "5px",
							"margin-bottom" : "40px"
						},
						align : "center"
					}
				},
//				modal : true,
				closable : false,
				defaults: {width: 730, margins: "5 0 5 0"},
				dockedItems: [
					{
						xtype: "toolbar",
						dock: "top",
						items: [
						   '->',
						   {
					    	   text: "Eliminar Grupo",
					    	   id: "instaladorEliminarTop",
							   iconCls: Asi.constants.icons.DELETE_ICON,
							   handler: Instalador.eliminarInstaladoresDeGrupo
					       },
					       {
					    	   text: "Guardar Grupo",
					    	   id: "instaladorGuardarTop",
							   iconCls: Asi.constants.icons.SAVE_ICON,
							   handler: Instalador.guardarGrupoInstaladores
					       }
					    ]
					}
	            ],
				items: [
					{
						xtype: "form",
						id: "instaladorForm",
						flex: 1,
					    border: false,
						layout: {
							type: "table",
							columns: 6,
							tableAttrs: {
					            style: {width: "730px"},
					            align: "center"
					        }
						},
						defaults: {
							width: 230,
							selectOnFocus: true,
							enforceMaxLength: true,
							maxLength: 200,
							typeAhead: true,
							minChars: 1,
							queryMode: "local",
							forceSelection: true,
							allowEnable: true,
							colspan: 2
						},
						
						items: [
								{
									xtype: "label",
									text: "Nombre de Grupo",
									cls: "x-form-item label_header",
									colspan: 6,
									width: 730
								},
								{xtype: "label", text:"Nombre:", cls: "x-form-item label_spacing", width : 230, colspan : 3},
								{
								 xtype: "textfield",
								 id: "NombreGrupo",
								 colspan:3
								}
								]
						
					},
					{
						xtype: "grid",
						id: "instaladorGrid",
						height: 240,
						width:730,
						collapsible: true,
						colspan: 6,
						plugins: [Ext.create('Ext.grid.plugin.CellEditing',{clicksToEdit: 1})],
						minHeight: 10,
						store: new Ext.data.SimpleStore({
					    	data: config.instaladoresDisponibles || [],
					    	fields: [
								"id",
								"login",
								"usuarioActivo"
			    	        ]
					    }),
					    columns: [
					              {header: "Id",  dataIndex: "id", flex: 1},
					              {header: "Usuario",  dataIndex: "login", flex: 1},
							      
							      {
							    	  	header: 'Activo',
							    	  	dataIndex: "usuarioActivo",
										align:'center',
										xtype:'checkcolumn',
										draggable: true,
										renderer : function(value){
									        var cssPrefix = Ext.baseCSSPrefix,
									            cls = [cssPrefix + 'grid-checkheader'];

									        if (value == "5" ||  value == 5 || value == false ||  value == "false") {
									            cls.push(cssPrefix + 'grid-checkheader-checked');
									        }
									        return '<div class="' + cls.join(' ') + '">&#160;</div>';
									    }

									}
					    ],
					listeners: {
				    	selectionchange: function(model, records){
				    		if(!records || records.length <= 0) return;
				    		var record = records[0];
				    		if(record != null){
				    			//Aqui se cargara el segundo gridview
				    			
				    			Instalador.cargarGridHijoPorIdPadre();
				    			
				    			
				    		}
				    	},
				    	
				    }
					},
					{
						xtype: "grid",
						id: "instaladorGrid2",
						height: 240,
						width:730,
						collapsible: true,
						colspan: 6,
						plugins: [Ext.create('Ext.grid.plugin.CellEditing',{clicksToEdit: 1})],
						minHeight: 10,
						store: new Ext.data.SimpleStore({
					    	data: config.instaladoresEnUso || [],
					    	groupers: [{property: "instaladorNombreGrupo"}],
					    	fields: [
								{name: "instaladorId"},
								{name: "instaladorNombreGrupo"},
								{name: "instaladorFechaCreacion"},
								{name: "instaladorEstado"},
								{name: "nombreInstalador"},
								{name: "nombreCreadorGrupo"}
			    	        ]
					    }),
					    columns: [
					              {header: "Id",  dataIndex: "instaladorId", flex: 1},
					              {header: "Instalador",  dataIndex: "nombreInstalador", flex: 1},
					              {header: "Fecha Creacion",  dataIndex: "instaladorFechaCreacion", flex: 1},
					              {header: "Creado Por",  dataIndex: "nombreCreadorGrupo", flex: 1},
					              {
							    	  	header: 'Eliminar?',
							    	  	dataIndex: "instaladorEstado",
										align:'center',
										xtype:'checkcolumn',
										draggable: true,
										renderer : function(value){
									        var cssPrefix = Ext.baseCSSPrefix,
									            cls = [cssPrefix + 'grid-checkheader'];

									        if (value == "0" ||  value == 0 || value == false ||  value == "false") {
									            cls.push(cssPrefix + 'grid-checkheader-checked');
									        }
									        return '<div class="' + cls.join(' ') + '">&#160;</div>';
									    }

									}
					    ],
					    features: [{
				        	   ftype: "grouping",
				        	   enableNoGroups: false,
				        	   groupHeaderTpl: 'Grupo: {name}'
				            }]
					}

				]
			});
			return configToReturn;
		}
	};
}();